<?php
/*
  PHP version 5
  Copyright (c) 2002-2010 ECISP.CN
  声明：这不是一个免费的软件，请在许可范围内使用

  作者：Bili E-mail:huangqyun@163.com  QQ:6326420
  http://www.ecisp.cn	http://www.easysitepm.com
 */
class mainpage extends connector {

	function mainpage() {
		$this->softbase(false);
		$this->mlink = $this->memberlink(array(), admin_LNG);
	}

	function in_index() {
		parent::start_pagetemplate();
		$lng = $this->CON['is_lancode'];
		$this->pagetemplate->assign('mlink', $this->mlink);
		$this->pagetemplate->assign('path', 'index');
		$codelist = hcitylist;
		$arr = explode(',',$codelist);
		$array = array();
		foreach($arr as $key=>$c) {
			$a = explode('|',$c);
			$array[] = array('id'=>$a[0],'name'=>$a[1]);
		}
		$this->pagetemplate->assign('array', $array);
		$keylink = $this->get_keytype_purview(101);  //读取首页关键字描述
		$arrkeylink = array();
		$arrkeylink['keytitle'] = str_replace('{#sitename#}',$this->lng['sitename'],$keylink['keytitle']);
		$arrkeylink['Keywords'] = str_replace('{#sitename#}',$this->lng['sitename'],$keylink['keyworklist']);
		$arrkeylink['Description'] = str_replace('{#sitename#}',$this->lng['sitename'],$keylink['description']);
		$this->pagetemplate->assign('arrkeylink', $arrkeylink);
		//目录不存在就生成目录
		if(!file_exists(admin_ROOT . "html/")) {
			mkdir(admin_ROOT . "html/");
		}
		//根目录下如果存在index.html也删除
		$filename2 = admin_ROOT . $this->CON['entrance_file'] .'.'.$this->CON['file_fileex'];
		if (file_exists($filename2)) {
			$this->fun->delfile($filename2);
		}
		$filename = admin_ROOT . "html/" . $this->CON['entrance_file'] .'.'.$this->CON['file_fileex'];
		//不存在则生成
		if (!file_exists($filename)) {
			$this->pagetemplate->display(admin_LNGDIR . 'index', 'index', true, $filename, admin_LNG);
		} else {
			$nowtime = time();
			$filetime = filemtime($filename);
			$cachetime = 2 * 3600;
			$endtime = $filetime + $cachetime;
			$exchchefiletime = $nowtime - $endtime;
			//如果过期则重新生成
			if($exchchefiletime >=0) {
				$this->pagetemplate->display(admin_LNGDIR . 'index', 'index', true, $filename, admin_LNG);
			}
		}
		$content = file_get_contents($filename);
		echo $content;
	}
	
	function in_friend() {
		parent::start_pagetemplate();
		$lng = (admin_LNG == 'big5') ? $this->CON['is_lancode'] : admin_LNG;
		$this->pagetemplate->assign('mlink', $this->mlink);
		
		$templatefilename = $templatecache = "";
		$templatefilename = $lng . '/article/friendlink_list';
		$templatecache = "friendlink_list";
		
		$this->pagetemplate->display($templatefilename, $templatecache, false, '', admin_LNG);
	}

	function in_seccodelist() {
		$seccode = rand(100000, 999999);
		$this->fun->setcookie('ecisp_home_seccode', $this->fun->eccode($seccode . "\t" . time(), 'ENCODE'));
		@header("Expires: -1");
		@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
		@header("Pragma: no-cache");
		include_once admin_ROOT . 'public/class_seccode.php';
		$code = new seccode();
		$code->code = $seccode;
		$code->type = 0;
		$code->width = 70;
		$code->height = 23;
		$code->background = 30;

		$code->adulterate = $this->CON['scode_adulterate'];

		$code->ttf = 0;
		$code->angle = 0;

		$code->color = 0;
		$code->size = 1;

		$code->shadow = $this->CON['scode_shadow'];
		$code->animator = 0;

		$code->bgcolor = $this->CON['scode_bgcolor'];

		$code->fontcolor = $this->CON['scode_fontcolor'];

		$code->datapath = admin_ROOT . 'datacache/';
		$code->includepath = '';
		$code->display();
	}
	
	/**
        $.get('index.php?ac=public&at=citylist&parentid=' + parentid + '&verid=' + verid, {},
        function(data) {
            $("#district").empty();
            $("#district").append(data)
        })
	 */

	function in_getcode() {
		$cityname = urldecode($this->fun->accept('cityname', 'R'));
		$db_table = db_prefix . 'hotelcity';
		$sql = "SELECT citycode,cityname FROM $db_table WHERE cityname like '%$cityname%'";
		$rs = $this->db->query($sql);
		$citylist = array();
		$i = 0;
		while ($rsList = $this->db->fetch_array($rs)) {
			$citylist[$i]['Id'] = $rsList['citycode'];
			$citylist[$i]['Name'] = $rsList['cityname'];
			$i++;
		}
		include_once admin_ROOT . 'public/class_json.php';
		$isjson = function_exists('json_decode')? true : false;
		$resstr = "";
		if($isjson) {
			$resstr = json_encode($citylist);
		} else {
			$json = new json();
			$resstr = $json->jsonEncode($citylist);
		}
		echo $resstr;
		exit;
	}
	function in_citylist() {
		$parentid = $this->fun->accept('parentid', 'R');
		$parentid = empty($parentid) ? 1 : intval($parentid);
		$verid = $this->fun->accept('verid', 'R');
		$verid = empty($verid) ? 0 : intval($verid);
		$db_table = db_prefix . 'city';
		$sql = "SELECT * FROM $db_table WHERE parentid=$parentid";
		$chacheview = $this->dbcache->checkcache('city_' . $parentid, false);
		if (!$chacheview) {
			$rs = $this->db->query($sql);
			while ($rsList = $this->db->fetch_array($rs)) {
				$citylist[] = $rsList;
			}
			$chacheview = $this->dbcache->cachesave('city_' . $parentid, $citylist);
			$chacheview = $chacheview ? $chacheview : $citylist;
			unset($citylist);
		}
		foreach ($chacheview as $key => $val) {
			if ($verid == $val['id']) {
				$list.='<option selected value="' . $val['id'] . '">' . $val['cityname'] . '</option>';
			} else {
				$list.='<option value="' . $val['id'] . '">' . $val['cityname'] . '</option>';
			}
		}
		if (admin_LNG == 'big5') {
			$list = $this->fun->codeing($list, 'gb');
		}
		exit($list);
	}
	
	function in_searchnearby() {
		$citycode = $this->fun->accept('citycode', 'G');
		$searchname = $this->fun->accept('searchname', 'G');
		$res = $this->get_hotel_nearby($citycode,$searchname);
		include_once admin_ROOT . 'public/class_json.php';
		$isjson = function_exists('json_decode')? true : false;
		$resstr = "";
		if($isjson) {
			$resstr = json_encode($res);
		} else {
			$json = new json();
			$resstr = $json->jsonEncode($res);
		}
		echo $resstr;
		exit;
	}
	
	//城市列表
	function in_hotelcitylist() {
		$res = $this->get_citylist(true,true,true);
		include_once admin_ROOT . 'public/class_json.php';
		$isjson = function_exists('json_decode')? true : false;
		$resstr = "";
		if($isjson) {
			$resstr = json_encode($res);
		} else {
			$json = new json();
			$resstr = $json->jsonEncode($res);
		}
		echo $resstr;
		exit;
	}
	////根据城市ID取得区域商圈等信息
	function in_hotelsinglecity() {
		$cityCode = $this->fun->accept('cityCode', 'G');
		$res = $this->get_singlecity($cityCode,true,true,true);
		$isjson = function_exists('json_decode')? true : false;
		$resstr = "";
		if($isjson) {
			$resstr = json_encode($res);
		} else {
			$json = new json();
			$resstr = $json->jsonEncode($res);
		}
		echo $resstr;
		exit;
	}

	function in_checkusername() {
		$username = $this->fun->accept('username', 'R');
		$email = $this->fun->accept('email', 'R');

		if (!preg_match("/^[^!@~`\'\"#\$\%\^&\*\(\)\+\-\{\}\[\]\|\\/\?\<\>\,\.\:\;]{2,16}$/i", $username) && !empty($username)) {
			exit('false');
		} elseif (!preg_match("/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/i", $email) && !empty($email)) {
			exit('false');
		}
		if ($this->CON['mem_isucenter']) {
			include_once admin_ROOT . 'public/uc_client/client.php';
			if (!empty($username)) {

				$data = uc_get_user($username);
				if ($data) {
					exit('false');
				}
			} elseif (!empty($email)) {
				$ucresult = uc_user_checkemail($email);
				if ($ucresult == -6 || $ucresult == -5) {
					exit('false');
				}
			}
		}
		$db_table = db_prefix . 'member';
		if (!empty($username)) {

			$lockusername = explode(',', $this->CON['mem_lock']);
			if (in_array($username, $lockusername)) {
				exit('false');
			}
			$db_where = " WHERE username='$username'";
		} elseif (!empty($email)) {
			$db_where = " WHERE email='$email'";
		}
		$countnum = $this->db_numrows($db_table, $db_where);
		if ($countnum > 0) {
			$exportAjax = 'false';
		} else {
			$exportAjax = 'true';
		}
		exit($exportAjax);
	}

	function in_typepuv() {
		if (!$this->CON['is_html']) {
			return true;
		}
		$tid = intval($this->fun->accept('tid', 'G'));
		$typeread = $this->get_type($tid);
		$userrank = $typeread['purview'];

		if ($typeread['styleid'] == 3) {
			$typelink = $this->get_link('type', $typeread, admin_LNG);
			$text = "javascript:location.href='" . $typelink . "';";
			exit($text);
		}
		if (!$userrank) {
			return true;
		}

		$this->ec_member_username = $this->fun->eccode($this->fun->accept('ecisp_member_username', 'C'), 'DECODE', db_pscode);

		$this->ec_member_username_id = $this->fun->accept('ecisp_member_username_id', 'C');
		$user_info = explode('|', $this->fun->eccode($this->fun->accept('ecisp_member_info', 'C'), 'DECODE', db_pscode));
		$mlink = $this->memberlink(array(), admin_LNG);
		if (empty($this->ec_member_username) || empty($this->ec_member_username_id)) {
			$this->fun->setcookie('ecisp_login_link', $_SERVER['HTTP_REFERER'], 3600);
			$linkURL = $this->get_link('memberlogin', array(), admin_LNG);
			if (admin_LNG == 'big5') {
				$str = $this->fun->codeing($this->lng['memberloginerr'], 'ub');
			} else {
				$str = $this->lng['memberloginerr'];
			}
			$text = "javascript:if (confirm('" . $str . "')){location.href='" . $linkURL . "'}else{location.href='" . $mlink['reg'] . "'};";
			exit($text);
		} else {
			list($this->ec_member_alias, $this->ec_member_integral, $this->ec_member_mcid, $this->ec_member_email, $this->ec_member_lastip) = $user_info;
			if ($this->ec_member_mcid < $userrank && $userrank) {
				$linkURL = $this->get_link('memberlogin', array(), admin_LNG);
				if (admin_LNG == 'big5') {
					$str = $this->fun->codeing($this->lng['memberpuverr'], 'ub');
				} else {
					$str = $this->lng['memberpuverr'];
				}
				$text = "javascript:if (confirm('" . $str . "')){location.href='" . $linkURL . "'}else{location.href='" . $mlink['reg'] . "'};";
				exit($text);
			}
		}
	}

	function in_readpuv() {
		if (!$this->CON['is_html']) {
			return true;
		}
		$did = intval($this->fun->accept('did', 'G'));
		if (empty($did)) {
			return false;
		}
		$readinfo = $this->get_documentview($did);
		if (empty($readinfo['tid'])) return false;
		$typeread = $this->get_type($readinfo['tid']);

		$userrank = $typeread['purview'];

		$userrank2 = $readinfo['purview'];
		if (!$readinfo['isclass']) {
			$text = "javascript:location.href='" . $this->CON['domain'] . "';";
			exit($text);
		}

		if ($readinfo['islink']) {
			$urladd = $readinfo['link'];
			$text = "javascript:location.href='" . $urladd . "';";
			exit($text);
		}

		$db_table = db_prefix . 'document';
		$db_where = "isclass=1 AND did=$did";
		$db_set = "click=click+1";
		$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
		if (!$userrank && !$userrank2) {

			return true;
		} elseif ($userrank < $userrank2) {

			$userrank = $userrank2;
		}

		$this->ec_member_username = $this->fun->eccode($this->fun->accept('ecisp_member_username', 'C'), 'DECODE', db_pscode);

		$this->ec_member_username_id = $this->fun->accept('ecisp_member_username_id', 'C');
		$user_info = explode('|', $this->fun->eccode($this->fun->accept('ecisp_member_info', 'C'), 'DECODE', db_pscode));
		$mlink = $this->memberlink(array(), admin_LNG);
		if (empty($this->ec_member_username) || empty($this->ec_member_username_id)) {
			$this->fun->setcookie('ecisp_login_link', $_SERVER['HTTP_REFERER'], 3600);
			$linkURL = $this->get_link('memberlogin', array(), admin_LNG);
			if (admin_LNG == 'big5') {
				$str = $this->fun->codeing($this->lng['memberloginerr'], 'ub');
			} else {
				$str = $this->lng['memberloginerr'];
			}
			$text = "javascript:if (confirm('" . $str . "')){location.href='" . $linkURL . "'}else{location.href='" . $mlink['reg'] . "'};";
			exit($text);
		} else {
			list($this->ec_member_alias, $this->ec_member_integral, $this->ec_member_mcid, $this->ec_member_email, $this->ec_member_lastip) = $user_info;
			if ($this->ec_member_mcid < $userrank && $userrank) {
				$linkURL = $this->get_link('memberlogin', array(), admin_LNG);
				if (admin_LNG == 'big5') {
					$str = $this->fun->codeing($this->lng['memberpuverr'], 'ub');
				} else {
					$str = $this->lng['memberpuverr'];
				}
				$text = "javascript:if (confirm('" . $str . "')){location.href='" . $linkURL . "'}else{location.href='" . $mlink['reg'] . "'};";
				exit($text);
			}
		}
	}

}
?>